﻿@page
@using global::AuthPermissions.AdminCode
@using LocalizeMessagesAndErrors
@using Microsoft.AspNetCore.Mvc.TagHelpers
@model Example1.RazorPages.IndividualAccounts.Pages.AuthUsers.SyncUsersModel
@inject ISimpleLocalizer SimpleLocalizer

@if (!@Model.Data.Any())
{
    <h3>
        @SimpleLocalizer.LocalizeString("There are no changes to apply to the AuthUsers", this)
    </h3>
    return;
}

<h3>
    @SimpleLocalizer.LocalizeString("Changes needed based on authentication provider's users", this)
</h3>
<form method="post">
    <table class="table">
        <thead>
            <tr>
                <th>@SimpleLocalizer.LocalizeString("Change type", this)</th>
                <th>@SimpleLocalizer.LocalizeString("Email", this)</th>
                <th>@SimpleLocalizer.LocalizeString("UserName", this)</th>
                <th>@SimpleLocalizer.LocalizeString("Roles count", this)</th>
            </tr>
        </thead>
        <tbody>
            @for (int i = 0; i < Model.Data.Count; i++)
            {
                <tr>
                    <td>
                        @SimpleLocalizer.LocalizeString(Model.Data[i].FoundChangeType.ToString(), this)
                        @Html.Hidden($"Data[{i}].{nameof(SyncAuthUserWithChange.UserId)}", Model.Data[i].UserId)
                        @Html.Hidden($"Data[{i}].{nameof(SyncAuthUserWithChange.FoundChangeType)}", Model.Data[i].FoundChangeType)
                    </td>

                    <td @(Model.Data[i].EmailChanged ? "class=bg-warning text-dark" : "")>
                        @Model.Data[i].Email
                        @Html.Hidden($"Data[{i}].{nameof(SyncAuthUserWithChange.Email)}", Model.Data[i].Email)
                    </td>
                    <td @(Model.Data[i].UserNameChanged ? "class=bg-warning text-dark" : "")>
                        @Model.Data[i].UserName
                        @Html.Hidden($"Data[{i}].{nameof(SyncAuthUserWithChange.UserName)}", Model.Data[i].UserName)
                    </td>
                    <td>@Model.Data[i].NumRoles</td>
                </tr>
            }

        </tbody>
    </table>

    <button class="btn btn-primary">@SimpleLocalizer.LocalizeString("Apply sync change", this)</button>
    <a class="btn btn-secondary" asp-area="" asp-page=".\ListUsers">
        @SimpleLocalizer.LocalizeString("Cancel", this)
    </a>
</form>


